class Product < ActiveRecord::Base
  belongs_to :procate
  has_one :pro_content,:dependent=>:delete
  has_many :pro_images,:dependent=>:delete_all,:conditions=>"img_type_id=2"
  has_many :peijians,:dependent=>:delete_all
  has_one :main_image,:class_name=>"ProImage",:dependent=>:delete,:conditions=>"img_type_id=1",:order=>"img_type_id"
  has_many :product_attribute_values,:dependent=>:delete_all
  has_one :tuangou_pro,:dependent=>:delete
  validates_presence_of :name,:price,:now_price
  has_many :pro_reviews,:dependent=>:delete_all
  has_many :cart_items
  has_many :carts,:through=>:cart_items

#  def get_value(column,template_id)
#    #if self.new_record?
#    temp=ProductAttributeValue.find(:first,:conditions=>"product_id=#{self.id} and product_attribute_template_id=#{template_id}")
#    temp.read_attribute(column) if temp
#    # end
#  end
end
